home *** CD-ROM | disk | FTP | other *** search
/ Mission 3 / Mission 3.zip / Mission 3.iso / texte / qed / src / icon.c < prev    next >
C/C++ Source or Header  |  1998-06-13  |  3KB  |  194 lines

  1. #include "global.h"
  2. #include "rsc.h"
  3. #include "set.h"
  4. #include "window.h"
  5. #include "icon.h"
  6.  
  7. #define    MAX_TYPE_ANZ    10
  8.  
  9. typedef struct
  10. {
  11.     void    (*exist)    (int obj_nr, SET actions);
  12.     bool    (*test)    (int obj_nr, int action);
  13.     int    (*edit)    (int obj_nr, int action);
  14.     bool    (*drag)    (int obj_nr, int dest_obj);
  15. } ICON_TYPE;
  16.  
  17. typedef ICON_TYPE *TYPEP;
  18.  
  19. typedef struct
  20. {
  21.     int    icon;
  22.     int    type_id;
  23. } ICON_TO_TYPE;
  24. typedef ICON_TO_TYPE *I2T;
  25.  
  26. static ICON_TYPE        icon[MAX_TYPE_ANZ];
  27. static ICON_TO_TYPE    i2t[MAX_ICON_ANZ];
  28. static int                type_anz = 0;
  29.  
  30. /* ============================================================== */
  31.  
  32. static TYPEP search_type(int obj_nr)
  33. {
  34.     int    i;
  35.     I2T    ic;
  36.  
  37.     obj_nr &= (~SUB_ICON);
  38.     for (ic=i2t,i=MAX_ICON_ANZ; (--i)>=0; ic++)
  39.         if (ic->icon==obj_nr)
  40.             return(icon+ic->type_id);
  41.     return(NULL);
  42. }
  43.  
  44. int all_icons(int *c)
  45. {
  46.     I2T    ic;
  47.     int    i, anz;
  48.  
  49.     ic = i2t;
  50.     for (i=MAX_ICON_ANZ, anz=0; (--i)>=0; ic++)
  51.         if (ic->icon!=-1)
  52.         {
  53.             *c++ = ic->icon;
  54.             anz++;
  55.         }
  56.     return anz;
  57. }
  58.  
  59. /* <0 : Fehler bei der Ausführung    */
  60. /*    =0 : Nicht möglich                    */
  61. /* >0 : Erfolgreich ausgeführt        */
  62. int do_icon(int icon, int action)
  63. {
  64.     TYPEP    t;
  65.  
  66.     t = search_type(icon);
  67.     if (t!=NULL && (t->test)(icon,action))
  68.         return (t->edit)(icon,action);
  69.     return 0;
  70. }
  71.  
  72. void do_all_icon(int type_id, int action)
  73. {
  74.     I2T    ic;
  75.     int    i;
  76.  
  77.     ic = i2t;
  78.     for (i=MAX_ICON_ANZ; (--i)>=0; ic++)
  79.         if (ic->icon!=-1 && (ic->type_id==type_id || type_id==ALL_TYPES))
  80.         {
  81.             do_icon(ic->icon, action);
  82.         }
  83. }
  84.  
  85. bool icon_test(int icon, int action)
  86. {
  87.     TYPEP    t;
  88.  
  89.     t = search_type(icon);
  90.     if (t!=NULL)
  91.         return (t->test)(icon,action);
  92.     return FALSE;
  93. }
  94.  
  95. int icon_edit(int icon, int action)
  96. {
  97.     TYPEP    t;
  98.  
  99.     t = search_type(icon);
  100.     if (t!=NULL)
  101.         return (t->edit)(icon,action);
  102.     return 0;
  103. }
  104.  
  105. void icon_exist(int icon, SET actions)
  106. {
  107.     TYPEP    t;
  108.  
  109.     t = search_type(icon);
  110.     if (t==NULL || t->exist==NULL)
  111.         setclr(actions);
  112.     else (t->exist)(icon,actions);
  113. }
  114.  
  115. bool icon_drag(int dest_obj, int src_obj)
  116. {
  117.     TYPEP    t;
  118.  
  119.     t = search_type(dest_obj);                        /* Ziel-Icon */
  120.     if (t==NULL || t->drag==NULL) return FALSE;
  121.     return((t->drag)(dest_obj,src_obj));
  122. }
  123.  
  124. int decl_icon_type(bool(*test)(int,int),
  125.                          int(*edit)(int,int),
  126.                          void(*exist)(int,SET),
  127.                          bool(*drag)(int,int))
  128. {
  129.     TYPEP    t;
  130.  
  131.     if (type_anz==MAX_TYPE_ANZ)
  132.         inote(1, 0, FATALERR, 12);
  133.     t = icon+type_anz;
  134.     t->exist    = exist;
  135.     t->test    = test;
  136.     t->edit    = edit;
  137.     t->drag    = drag;
  138.     type_anz++;
  139.     return (type_anz-1);
  140. }
  141.  
  142. bool add_icon(int type_id, int obj_nr)
  143. {
  144.     int    i;
  145.     I2T    ic;
  146.  
  147.     ic = i2t;
  148.     for (i=MAX_ICON_ANZ; (--i)>=0; ic++)
  149.         if (ic->icon==-1)
  150.         {
  151.             ic->icon = obj_nr;
  152.             ic->type_id = type_id;
  153.             return TRUE;
  154.         }
  155.     return FALSE;
  156. }
  157.  
  158. void del_icon(int obj_nr)
  159. {
  160.     I2T    ic;
  161.     int    i;
  162.  
  163.     ic = i2t;
  164.     for (i=MAX_ICON_ANZ; (--i)>=0; ic++)
  165.         if (ic->icon==obj_nr)
  166.         {
  167.             ic->icon = -1;
  168.             return;
  169.         }
  170.     inote(1, 0, FATALERR, 1);
  171. }
  172.  
  173. int icon_anz(int type_id)
  174. {
  175.     I2T    ic;
  176.     int    i, anz;
  177.  
  178.     anz = 0;
  179.     ic = i2t;
  180.     for (i=MAX_ICON_ANZ; (--i)>=0; ic++)
  181.         if (ic->type_id==type_id || type_id==ALL_TYPES)
  182.             anz++;
  183.     return anz;
  184. }
  185.  
  186. void init_icon(void)
  187. {
  188.     int    i;
  189.     I2T    ic = i2t;
  190.  
  191.     for (i=MAX_ICON_ANZ; (--i)>=0; ic++)
  192.         ic->icon = -1;
  193. }
  194.